﻿using System.Diagnostics;
using System;

namespace EmbeddedSharp.Core.Logging {
    public class EventLogger : ILogger {
        private EventLog el = null;

        public EventLogger(string logName) {
            if (!EventLog.SourceExists(logName)) {
                EventLog.CreateEventSource(logName, logName);
            }

            el = new EventLog(logName, Environment.MachineName, logName);
        }

        #region ILogManager Members

        public void WriteLog(string message, params string[] args) {
            el.WriteEntry(string.Format(message, args));
        }

        public void WriteLog(Exception ex) {
            el.WriteEntry(string.Format("{0}:{1}", ex.Message, ex.StackTrace));
        }

        #endregion
    }
}
